

package com.ifeiyang.bijia.model;


import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.LinearInterpolator;
import android.widget.PopupWindow;


import com.lidroid.xutils.util.LogUtils;
import com.nineoldandroids.animation.Animator.AnimatorListener;
import com.nineoldandroids.animation.Animator;
import com.nineoldandroids.animation.AnimatorSet;
import com.nineoldandroids.animation.ObjectAnimator;


public class AnimaModel {


	interface AnimListener {


		void onAnimationEnd(Animator arg0);


		void onAnimationStart(Animator arg0);

	}


	public static void startUP(final View view, boolean ifStart, final int dx, final int dy,
			final AnimListener animListener) {


		AnimatorSet set = new AnimatorSet();
		ObjectAnimator translationX = ObjectAnimator.ofFloat(view, "translationX", 0, dx);
		ObjectAnimator translationY = ObjectAnimator.ofFloat(view, "translationY", 0, dy);
		translationX.setInterpolator(new LinearInterpolator());
		translationY.setInterpolator(new AccelerateInterpolator());

		/**
		 * final float mideScale = 1f; final float endScale = 0.5f; ,
		 * ObjectAnimator.ofFloat(view, "scaleX", 1f, mideScale),
		 * ObjectAnimator.ofFloat(view, "scaleY", 1f, mideScale)
		 */
		set.playTogether(translationX, translationY);
		set.setDuration(600);

		set.addListener(new AnimatorListener() {


			@Override
			public void onAnimationStart(com.nineoldandroids.animation.Animator arg0) {


				animListener.onAnimationStart(arg0);
			}


			@Override
			public void onAnimationRepeat(com.nineoldandroids.animation.Animator arg0) {


			}


			@Override
			public void onAnimationEnd(com.nineoldandroids.animation.Animator arg0) {


				animListener.onAnimationEnd(arg0);

			}


			@Override
			public void onAnimationCancel(com.nineoldandroids.animation.Animator arg0) {


			}
		});
		if (ifStart) {
			set.start();
		}


	}


	public static void startList(final View view, boolean ifStart, final int dx, final int dy,
			final AnimListener animListener) {


		AnimatorSet set = new AnimatorSet();
		ObjectAnimator translationX = ObjectAnimator.ofFloat(view, "translationX", 0, dx);
		ObjectAnimator translationY = ObjectAnimator.ofFloat(view, "translationY", 0, dy);
		translationX.setInterpolator(new LinearInterpolator());
		translationY.setInterpolator(new DecelerateInterpolator());

		/**
		 * final float mideScale = 1f; final float endScale = 0.5f; ,
		 * ObjectAnimator.ofFloat(view, "scaleX", 1f, mideScale),
		 * ObjectAnimator.ofFloat(view, "scaleY", 1f, mideScale)
		 */
		set.playTogether(translationX, translationY);
		set.setDuration(600);
		set.addListener(new AnimatorListener() {


			@Override
			public void onAnimationStart(com.nineoldandroids.animation.Animator arg0) {


				animListener.onAnimationStart(arg0);
			}


			@Override
			public void onAnimationRepeat(com.nineoldandroids.animation.Animator arg0) {


			}


			@Override
			public void onAnimationEnd(com.nineoldandroids.animation.Animator arg0) {


				animListener.onAnimationEnd(arg0);

			}


			@Override
			public void onAnimationCancel(com.nineoldandroids.animation.Animator arg0) {


			}
		});
		
		LogUtils.d("set="+set);
		LogUtils.d("view="+view);
		if (ifStart) {
			set.start();
		}


	}


	// public static void startUP2(final View view, boolean ifStart, final int
	// des,
	// final AnimListener animListener) {
	//
	//
	// final float mideScale = 1.2f;
	// final float endScale = 0.3f;
	//
	// AnimatorSet set = new AnimatorSet();
	// set.playTogether(ObjectAnimator.ofFloat(view, "translationX", 0, -50),
	// ObjectAnimator.ofFloat(view, "translationY", 0, -300),
	// ObjectAnimator.ofFloat(view, "scaleX", 1f, mideScale),
	// ObjectAnimator.ofFloat(view, "scaleY", 1f, mideScale));
	// set.setInterpolator(new DecelerateInterpolator());
	// set.setDuration(200);
	// set.addListener(new AnimatorListener() {
	//
	//
	// @Override
	// public void onAnimationStart(com.nineoldandroids.animation.Animator arg0)
	// {
	//
	//
	// animListener.onAnimationStart(arg0);
	// }
	//
	//
	// @Override
	// public void onAnimationRepeat(com.nineoldandroids.animation.Animator
	// arg0) {
	//
	//
	// }
	//
	//
	// @Override
	// public void onAnimationEnd(com.nineoldandroids.animation.Animator arg0) {
	//
	//
	// AnimatorSet set = new AnimatorSet();
	// set.playTogether(ObjectAnimator.ofFloat(view, "translationX", -50, +50),
	// ObjectAnimator.ofFloat(view, "translationY", -300, des),
	// ObjectAnimator.ofFloat(view, "scaleX", mideScale, endScale),
	// ObjectAnimator.ofFloat(view, "scaleY", mideScale, endScale));
	// set.setInterpolator(new AccelerateInterpolator());
	// set.setDuration(300);
	// set.addListener(new AnimatorListener() {
	//
	//
	// @Override
	// public void onAnimationStart(Animator arg0) {
	//
	//
	// }
	//
	//
	// @Override
	// public void onAnimationRepeat(Animator arg0) {
	//
	//
	// }
	//
	//
	// @Override
	// public void onAnimationEnd(Animator arg0) {
	//
	//
	// // TODO Auto-generated method stub
	// animListener.onAnimationEnd(arg0);
	//
	// }
	//
	//
	// @Override
	// public void onAnimationCancel(Animator arg0) {
	//
	//
	// }
	// });
	// set.start();
	//
	// }
	//
	//
	// @Override
	// public void onAnimationCancel(com.nineoldandroids.animation.Animator
	// arg0) {
	//
	//
	// }
	// });
	// if (ifStart) {
	// set.start();
	// }
	//
	// }


	//
	// public static void startList2(final View view, boolean ifStart, final int
	// dx, final int dy,
	// final AnimListener animListener) {
	//
	//
	// final float mideScale = 1.2f;
	// final float endScale = 0.5f;
	// AnimatorSet set = new AnimatorSet();
	// set.playTogether(ObjectAnimator.ofFloat(view, "translationX", 0, -50),
	// ObjectAnimator.ofFloat(view, "translationY", 0, dy / 3),
	// ObjectAnimator.ofFloat(view, "scaleX", 1f, mideScale),
	// ObjectAnimator.ofFloat(view, "scaleY", 1f, mideScale));
	// set.setInterpolator(new DecelerateInterpolator());
	// set.setDuration(200);
	// set.addListener(new AnimatorListener() {
	//
	//
	// @Override
	// public void onAnimationStart(com.nineoldandroids.animation.Animator arg0)
	// {
	//
	//
	// animListener.onAnimationStart(arg0);
	// }
	//
	//
	// @Override
	// public void onAnimationRepeat(com.nineoldandroids.animation.Animator
	// arg0) {
	//
	//
	// }
	//
	//
	// @Override
	// public void onAnimationEnd(com.nineoldandroids.animation.Animator arg0) {
	//
	//
	// AnimatorSet set = new AnimatorSet();
	// set.playTogether(ObjectAnimator.ofFloat(view, "translationX", -50, dx),
	// ObjectAnimator.ofFloat(view, "translationY", dy / 3, dy),
	// ObjectAnimator.ofFloat(view, "scaleX", mideScale, endScale),
	// ObjectAnimator.ofFloat(view, "scaleY", mideScale, endScale));
	// set.setInterpolator(new AccelerateInterpolator());
	// set.setDuration(300);
	// set.addListener(new AnimatorListener() {
	//
	//
	// @Override
	// public void onAnimationStart(Animator arg0) {
	//
	//
	// }
	//
	//
	// @Override
	// public void onAnimationRepeat(Animator arg0) {
	//
	//
	// }
	//
	//
	// @Override
	// public void onAnimationEnd(Animator arg0) {
	//
	//
	// // TODO Auto-generated method stub
	// animListener.onAnimationEnd(arg0);
	//
	// }
	//
	//
	// @Override
	// public void onAnimationCancel(Animator arg0) {
	//
	//
	// }
	// });
	// set.start();
	//
	// }
	//
	//
	// @Override
	// public void onAnimationCancel(com.nineoldandroids.animation.Animator
	// arg0) {
	//
	//
	// }
	// });
	// if (ifStart) {
	// set.start();
	// }
	//
	// }
}
